package com.xsmart.oa.dao.mall.mymenu;

import com.xsmart.common.entity.user.SellerShopInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
public interface UserApplyDao {


    @Insert("insert into infu_user_request_type_task(user_id,task_type,create_time,status) " +
            "values(#{userId},#{taskType},NOW(),0)")
    int addTask(@Param("userId") Integer userId, @Param("taskType") Integer taskType);

    @Insert("insert into seller_shopinfo(ru_id,shop_name,shop_title,shop_keyword,shop_address,seller_email,kf_qq,kf_ww," +
            "kf_tel,mobile,notice,status,audit_status,country,province,city,district) values(#{shopInfo.ruId},#{shopInfo.shopName},#{shopInfo.shopTitle},#{shopInfo.shopKeyword}," +
            "#{shopInfo.shopAddress},#{shopInfo.sellerEmail},#{shopInfo.kfqq},#{shopInfo.kfww},#{shopInfo.kfTel},#{shopInfo.mobile}," +
            "#{shopInfo.notice},#{shopInfo.status},0,#{shopInfo.country},#{shopInfo.province},#{shopInfo.city},#{shopInfo.district})")
    int addSellerShop(@Param("shopInfo") SellerShopInfo shopInfo);

//    @Select("select * from infu_user_request_type_task where user_id=#{userId} order by create_time DESC LIMIT 1")
    @Select("select * from (select * from infu_user_request_type_task where user_id=#{userId} and task_type = 0 ORDER BY create_time desc LIMIT 1) a " +
            " UNION all " +
            "select * from (select * from infu_user_request_type_task where user_id=#{userId} and task_type = 1 ORDER BY create_time desc LIMIT 1) b")
    List<Map<String,Object>> queryTaskByUserId(@Param("userId") Integer userId);


}
